package com.ktjy.service;

import com.ktjy.dao.PetDao;
import com.ktjy.dao.impl.PetDaoOracleImpl;
import com.ktjy.entity.Pet;

import jakarta.annotation.Resource;

import org.springframework.stereotype.Service;

@Service("petService")
public class PetServiceImpl implements PetService {
//    PetDao petDao = PetDaoFactory.getInstance(PetDaoFactory.defaultBeanName);

//    @Autowired
    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;

    public PetDao getPetDao() {return petDao;}

    public void setPetDao(PetDao petDao) {this.petDao = petDao;}

    @Override
    public boolean sava(Pet pet) {
//        return petDao.insert(pet) > 0;
        int rows = petDao.insert(pet);
//        if(true){
//            throw new RuntimeException("业务操作异常！");
//        }
        delay(3000);
        return rows > 0;
    }

    @Override
    public boolean modify(Pet pet) {
        delay(2000);
        return false;
    }

    @Override
    public boolean del(Integer id) {
        delay(1000);
        return false;
    }

    public void delay(int time){
        try{
            Thread.sleep(time);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
